//
//  MessageCell.m
//  WashCar
//
//  Created by 张越 on 16/3/25.
//  Copyright © 2016年 张越. All rights reserved.
//

#import "MessageCell.h"

@implementation MessageCell

- (void)awakeFromNib {
    self.BackgroundView.layer.cornerRadius = 5.0f;
    self.BackgroundView.layer.masksToBounds = YES;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (void)setMessageModel:(MessageModel *)messageModel
{
    if (_messageModel != messageModel) {
        _messageModel = messageModel;
    }
    self.contLabel.text = messageModel.cont;
    self.timeLabel.text = messageModel.time;
    
    CGRect labelRect = self.contLabel.frame;
    labelRect.size.height = [[self class] labelHeight:messageModel.cont];
    self.contLabel.frame = labelRect;
    
}

//文本高度
+ (CGFloat)labelHeight:(NSString *)label {
    //文本渲染的是需要的矩形大小,按要求,宽度要和文本大小的宽是一样的,必须是固定值
    CGSize contentSize = CGSizeMake(ScreenWidth - 105, 0);
    //计算时设置的文本大小,必须要和我们显示文本的label上设定的字体大小保持一致
    NSDictionary *attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:14.0f]};
    //计算时设置的文本大小,必须要和我们显示文本的label上设定的字体大小保持一致
    CGRect labelRect = [label boundingRectWithSize:contentSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attribute context:nil];
    //返回计算得到的高度
    return labelRect.size.height;
}

+ (CGFloat)cellHeight:(MessageModel *)messageModel {
    //计算可变的label的高度
    CGFloat labelRect = [self labelHeight:messageModel.cont];
    //返回不可变 + 可变
    return 20 + 10 + 15 + 40 + 32 + labelRect;
    
}



@end
